package cn.kgc.controller;

import cn.kgc.entity.Group;
import cn.kgc.service.GroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author mosin
 * date 2022/1/17
 * @version 1.0
 */
@RestController
@RequestMapping("/groups")
public class GroupController {
    @Autowired
    private GroupService groupService;

    //查询小组列表
    @GetMapping
    public List<Group> getAll(){
        List<Group> groups =  groupService.queryAll();
       return groups;
    }

    //添加小组
    @PostMapping
    public Group  addGroup(@RequestBody Group group){
        Group  gp  =  groupService.addGroup(group);
        return gp;
    }

    //根据 id 查询小组信息
    @GetMapping("/{id}")
    public Group group(@PathVariable Integer id){

        Group group =  groupService.getOne(id);
        return  group;
    }


}
